package api.txBanner;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import java.lang.ref.SoftReference;

/**
 * Banner模式
 */
public abstract class BannerAPI_TX {

    public static String clazz = "api.txBanner.TX_Banner";

    private static SoftReference<BannerAPI_TX> sf;

    public synchronized static BannerAPI_TX getInstance() {

        if (sf == null || sf.get() == null) {
            Object o = null;
            try {
                o = Class.forName(clazz).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (o != null) {
                sf = new SoftReference<>((BannerAPI_TX)o);
                return (BannerAPI_TX)o;
            }
        }
        return sf == null ? null : sf.get();
    }

    /**
     * @param context
     * @param BannerID
     * @param refreshTime 设置刷新频率,为0或30~120之间的数字，单位为 s,0标识不自动轮播,默认30S
     * @param callBack
     * @return
     */
    public abstract View loadBanner(Activity context, ViewGroup bannerContainer,String BannerID, int refreshTime, LoadBannerCallBack callBack);

    public abstract void bannerDestroy();
    public interface LoadBannerCallBack {
        void onNoBanner(String code, String msg);
        void onBannerReceiv(); //广告加载成功回调，表示广告相关的资源已经加载完毕，Ready To Show
        void onBannerExposure(); //当广告曝光时发起的回调
        void onBannerClicked();
        void onBannerClosed();  //当广告关闭时调用
        void onBannerLeftApplication();//由于广告点击离开 APP 时调用
    }

}
